home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / MiniGL / demos / smtest.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-07  |  1.8 KB  |  77 lines

  1. // This demo demonstrates the "Amiga-specific" display features, like
  2. // screenmode callbacks, and access of the back buffer
  3.  
  4. #include <stdio.h>
  5. #include <mgl/gl.h>
  6. #include <proto/dos.h>          // For Delay()
  7.  
  8. GLboolean ScreenModeCallback(MGLScreenMode *mode)
  9. {
  10.     printf("ModeID: %d\n", mode->id);
  11.     printf("   Size is %d×%d\n", mode->width, mode->height);
  12.     printf("   Depth is %d\n", mode->bit_depth);
  13.     printf("   Name is %s\n", mode->mode_name);
  14.     printf("\n");
  15.     return GL_FALSE;
  16. }
  17.  
  18. GLboolean ScreenModeCallback2(MGLScreenMode *mode)
  19. {
  20.     if (mode->width == 320 && mode->bit_depth==16) return GL_TRUE;
  21.     else return GL_FALSE;
  22. }
  23.  
  24. int main(int argc, char **argv)
  25. {
  26.     GLint id;
  27.     GLint w, h;
  28.     MGLLockInfo li;
  29.  
  30.     MGLInit();
  31.  
  32.     printf("Getting all modes:\n");
  33.     id = mglGetSupportedScreenModes(ScreenModeCallback);
  34.     printf("(Returned id %d)\n",id);
  35.     printf("\n\nTrying to find a mode that satisfies ""Width==320"" and ""bit_depth==16""\n");
  36.  
  37.     id = mglGetSupportedScreenModes(ScreenModeCallback2);
  38.     printf("Returned id is %d\n", id);
  39.  
  40.     if (argc == 2 && 0 == stricmp(argv[1],"-window"))
  41.     {
  42.         mglChooseWindowMode(GL_TRUE);
  43.     }
  44.  
  45.  
  46.     mglCreateContext(0, 0, 320, 240);
  47.  
  48.     if (mglLockBack(&li))
  49.     {
  50.         glClearColor(0.0, 0.0, 0.0, 0.0);
  51.         glClear(GL_COLOR_BUFFER_BIT);
  52.         glFinish();             // <--- Note this glFinish(); It ensures that the clear operation
  53.                                 //      is really done when we access the back buffer
  54.  
  55.         memset(li.base_address, 0xff, 20);
  56.         mglUnlockDisplay();
  57.         mglSwitchDisplay();
  58.         Delay(100);
  59.  
  60.  
  61.         printf("Display info:\nDimensions:%d×%d×%d\n", li.width, li.height, li.depth);
  62.         printf("Pixel format: %d\n", li.pixel_format);
  63.         printf("Base address: 0x%x\n", li.base_address);
  64.         printf("Pitch: %d\n", li.pitch);
  65.     }
  66.     else
  67.     {
  68.         printf("Unable to lock back buffer\n");
  69.     }
  70.  
  71.     mglDeleteContext();
  72.  
  73.     MGLTerm();
  74.  
  75.     return 0;
  76. }
  77.